package cn.edu.sdjzu.xg.eagle.service;

import cn.edu.sdjzu.xg.eagle.dao.SchoolDao;
import cn.edu.sdjzu.xg.eagle.entity.School;
import cn.edu.sdjzu.xg.eagle.exception.BysjException;
import cn.edu.sdjzu.xg.eagle.util.Condition;
import cn.edu.sdjzu.xg.eagle.util.Pagination;

import java.sql.SQLException;
import java.util.Collection;

public class SchoolService {
    // 单例实例
    private static SchoolService instance;

    // 私有构造函数
    private SchoolService() {}

    // 获取单例实例
    public static SchoolService getInstance() {
        if (instance == null) {
            instance = new SchoolService();
        }
        return instance;
    }

    public boolean add(School schoolToAdd) throws SQLException, BysjException {
        SchoolDao.getInstance().add(schoolToAdd);
        return false;
    }

    // 查询所有学校
    public Collection<School> findAll() throws BysjException, SQLException {
        return SchoolDao.getInstance().findAll( null);
    }

    // 根据条件查询学校
    public Collection<School> findAll(Collection<Condition> conditions) throws BysjException, SQLException {
        return SchoolDao.getInstance().findAll((Pagination) conditions);
    }

    // 根据分页和条件查询学校
    public Collection<School> findAll(Pagination pagination, Collection<Condition> conditions) throws BysjException, SQLException {
        return SchoolDao.getInstance().findAll(pagination);
    }
}

